#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 5e4 + 10;
int n;
struct node
{
    int sum, w, s;
}s[N];
int cmp(node a, node b)
{
    return a.sum < b.sum;
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s[i].w >> s[i].s;
        s[i].sum = s[i].w + s[i].s;
    }
    sort(s, s + n, cmp);
    int ans = -1e9;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, sum - s[i].s);
        sum += s[i].w;
    }
    cout << ans << endl;
    return 0;
}